home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Tools&Utilities / CreditCheck / ReadMe (SimpleText) < prev   
Text File  |  1996-04-19  |  3KB  |  95 lines

  1. CreditCheck 1.0
  2.  
  3. A utility for checking the validity of credit card numbers.
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13. This version by Peter Marks.
  14.  
  15. Type in the number and press return or enter to check it. Beeps if bad. Also displays the type of card including: Amex, Mastercard, Visa, Diners, Australian BankCard & Discover.
  16.  
  17. Based on the algorithm presented in Check Numbers 1.0 by René G. A. Ros who says:
  18.  
  19. “FileMaker Pro 3.0 example scripts to check the validity of Credit Card, EAN and of ISBN codes.
  20. Ported to FileMaker Pro 3.0 by René G.A. Ros (rgaros@bio.vu.nl)
  21. Based on earlier ports to 4th Dimension by the same author. This 4D code was based on, and extended because of, information made available on the Internet by Diomidis Spinellis (dds@doc.ic.ac.uk), Peter Rukavina (peter@crafs-council.pe.ca) and Florian Dejako (fdj@muc.de).
  22. Try to get it into calculation fields!”
  23.  
  24. This version of the algorithm has been put into a c++ program based on the Metrowerks PowerPlant “Dashboard” sample.
  25.  
  26. Here are the two interesting methods, (note that I use the string library class that comes with PowerPlant):
  27.  
  28. // work out the card type by looking at first and second digits
  29. void CDashboardApp::GetCardType(LStr255& outCardName, LStr255& inNumber)
  30. {
  31.     if((inNumber[1] == '3') && (inNumber[2] == '7'))
  32.         outCardName = "American Express";
  33.     else if((inNumber[1] == '5') && (inNumber[2] == '6'))
  34.         outCardName = "BankCard";
  35.     else if(inNumber[1] == '3')
  36.         outCardName = "Diner’s Club";
  37.     else if(inNumber[1] == '5')
  38.         outCardName = "MasterCard";
  39.     else if(inNumber[1] == '4')
  40.         outCardName = "Visa";
  41.     else if(inNumber[1] == '6')
  42.         outCardName = "Discover";
  43.     else
  44.         outCardName = "Unknown";
  45. }
  46.  
  47. // return true if the last digit is the correct checksum digit
  48. Boolean CDashboardApp::CheckSum(LStr255& inNumber)
  49. {
  50.     short length = inNumber.Length();
  51.     char lastChar = inNumber[length];    
  52.     // the checkSum we are looking for
  53.     
  54.     short checkSum = 0;
  55.     for(short i = 1; i < length; i++)    
  56.     {
  57.         // don't include the last digit
  58.  
  59.         short digit = inNumber[length - i] - '0';    
  60.                     // get the digits from r to l
  61.         short temp = digit * (1 + (i % 2));
  62.         if(temp < 10)
  63.             checkSum += temp;
  64.         else
  65.             checkSum += temp - 9;
  66.     }
  67.     checkSum = (10 - (checkSum % 10)) % 10;
  68.     
  69.     if((lastChar - '0') == checkSum)
  70.         return true;
  71.     else
  72.         return false;
  73. }
  74.  
  75. Future enhancements:
  76.  
  77. •    AppleScript API to allow it to check numbers for other programs, although it’s probably better to just convert the algorithm (which I’ve provided above) and put it in the client program.
  78.  
  79. Notes
  80.  
  81. The program creates a small prefs file (317 bytes) in your preference folder that holds the last number you had in the window and also the window position.
  82.  
  83.  
  84.  
  85.  
  86.  
  87. This particular implementation is © 1996, Peter Marks. All credit to the folks listed above who described the algorithm and made it freely available. Thanks also to Metrowerks for making Codewarrior and providing the great PowerPlant samples.
  88.  
  89. I take no responsibility for errors or bugs in this software.
  90.  
  91. Please report any problems you find to me by email:
  92.  
  93. Peter.Marks@pobox.com
  94. <http://www.pobox.com/~peter.marks>
  95.